package bairui.international.model.domain.jpa;

import com.lianjing.sh.model.uml.model.data.TBSuper_BaseIDAndTimeAndOrderValue;

/**
 *
 * (城市)TB_City
 *
 * @说明
 * <pre>

 * </pre>
 *
 * @see Help_TB_City#inheritance() 继承体系信息
 *
 */
@org.hibernate.annotations.DynamicInsert
@org.hibernate.annotations.DynamicUpdate

@javax.persistence.Entity(name="t_city")
@com.lianjing.sh.processing.info.annotation.GenerateInfoModel
@SuppressWarnings("serial")
@com.lianjing.sh.model.common.annotation.Comment("城市")
@com.lianjing.sh.processing.info.annotation.InfoComment("城市")
public class TB_City
 extends TBSuper_BaseIDAndTimeAndOrderValue
 implements 
	com.lianjing.sh.model.common.stardard.TableModel<Long>,
	java.io.Serializable

{

	
	
	/**
	 * 必须属性赋值接口
	 */
	public static interface MustProperties{
		/** 省份 */
		public bairui.international.model.domain.jpa.TB_Province getProvince();
		/** 名称 */
		public String getName();
		/** 代码 */
		public String getCode();
	}
	
	/**
	 * 为必须属性赋值
	 */
	public TB_City properties(MustProperties properties) {
		this.setProvince(properties.getProvince());
		this.setName(properties.getName());
		this.setCode(properties.getCode());
		return this;
	}
	
	/**
	 *	必须属性构造函数
	 */
	public TB_City(MustProperties properties) {
		this.properties(properties);
	}
	
	
	/**
	 * 可选单属性赋值接口
	 */
	public static interface OptionalSingleProperties{
	}
	
	/**
	 * 为可选单属性赋值
	 */
	public TB_City properties(OptionalSingleProperties properties) {
		return this;
	}
	
	
	
	public TB_City(MustProperties must, OptionalSingleProperties optionalSingle) {
		this.properties(must);
		this.properties(optionalSingle);
	}
	
	/**
	 * 仅当前必须属性赋值接口
	 */
	public static interface CurrentMustProperties{
		/** 省份 */
		public bairui.international.model.domain.jpa.TB_Province getProvince();
		/** 名称 */
		public String getName();
		/** 代码 */
		public String getCode();
	}
	
	/**
	 * 为仅当前必须属性赋值
	 */
	public TB_City properties(CurrentMustProperties properties) {
		this.setProvince(properties.getProvince());
		this.setName(properties.getName());
		this.setCode(properties.getCode());
		return this;
	}
	
	/**
	 * 仅当前可选单属性赋值接口
	 */
	public static interface CurrentOptionalSingleProperties{
	}
	
	/**
	 * 为仅当前可选单属性赋值
	 */
	public TB_City properties(CurrentOptionalSingleProperties properties) {
		return this;
	}
	
	public TB_City(
		@lombok.NonNull com.lianjing.sh.model.uml.model.data.TBSuper_BaseIDAndTimeAndOrderValue bean,
		CurrentMustProperties mustProperties,
		CurrentOptionalSingleProperties optionalProperties
	) {
		this(bean);
		this.properties(mustProperties);
		this.properties(optionalProperties);
	}
	
	public TB_City(
		@lombok.NonNull com.lianjing.sh.model.uml.model.data.TBSuper_BaseIDAndTimeAndOrderValue bean
	) {
		update(bean);
	}
	
	public TB_City update(com.lianjing.sh.model.uml.model.data.TBSuper_BaseIDAndTimeAndOrderValue bean){
		this.setId(bean.getId());
		this.setCreateTime(bean.getCreateTime());
		this.setModifyTime(bean.getModifyTime());
		this.setOrderValue(bean.getOrderValue());
		return this;
	}
	
	
	/**
	 * 更新属性内部类
	 */
	public abstract class UpdateProperties {
	
		public UpdateProperties() throws Exception {
			Integer orderValue = getOrderValue(TB_City.this);
			if(isOverride_getOrderValue){
				TB_City.this.setOrderValue(orderValue);
			}
	
			java.util.List<bairui.international.model.domain.jpa.TB_Town> towns = getTowns(TB_City.this);
			if(isOverride_getTowns){
				TB_City.this.setTowns(towns);
			}
	
			bairui.international.model.domain.jpa.TB_Province province = getProvince(TB_City.this);
			if(isOverride_getProvince){
				TB_City.this.setProvince(province);
			}
	
			String name = getName(TB_City.this);
			if(isOverride_getName){
				TB_City.this.setName(name);
			}
	
			String code = getCode(TB_City.this);
			if(isOverride_getCode){
				TB_City.this.setCode(code);
			}
		}
	
		public TB_City up(){
			return TB_City.this;
		}
	
		/** 排序值 */
		private boolean isOverride_getOrderValue = true;
		public Integer getOrderValue(TB_City it) throws Exception { 
			isOverride_getOrderValue = false; 
			return null;
		}
		/** 区县 */
		private boolean isOverride_getTowns = true;
		public java.util.List<bairui.international.model.domain.jpa.TB_Town> getTowns(TB_City it) throws Exception { 
			isOverride_getTowns = false; 
			return null;
		}
		/** 省份 */
		private boolean isOverride_getProvince = true;
		public bairui.international.model.domain.jpa.TB_Province getProvince(TB_City it) throws Exception { 
			isOverride_getProvince = false; 
			return null;
		}
		/** 名称 */
		private boolean isOverride_getName = true;
		public String getName(TB_City it) throws Exception { 
			isOverride_getName = false; 
			return null;
		}
		/** 代码 */
		private boolean isOverride_getCode = true;
		public String getCode(TB_City it) throws Exception { 
			isOverride_getCode = false; 
			return null;
		}
	
	}
	
	
	/**
	 * 构造函数
	 */
	public TB_City() {
	}
	
	public TB_City(
		@lombok.NonNull Long id
	) {
		this.setId(id);
	}
	
	public TB_City(
		@lombok.NonNull TB_City bean
	) {
		this.setId(bean.getId());
		this.setCreateTime(bean.getCreateTime());
		this.setModifyTime(bean.getModifyTime());
		this.setOrderValue(bean.getOrderValue());
		this.setTowns(bean.getTowns());
		this.setProvince(bean.getProvince());
		this.setName(bean.getName());
		this.setCode(bean.getCode());
	}
	
	

	


	/**
	 * 属性
	 */
	@com.lianjing.sh.model.common.annotation.Comment("区县")
	@com.lianjing.sh.processing.info.annotation.InfoComment("区县")
	@com.querydsl.core.annotations.QueryInit("*.*.*")
	@javax.persistence.OneToMany(cascade={javax.persistence.CascadeType.ALL}, mappedBy="city")
	private java.util.List<bairui.international.model.domain.jpa.TB_Town> towns;

	@com.lianjing.sh.model.common.annotation.Comment("省份")
	@com.lianjing.sh.processing.info.annotation.InfoComment("省份")
	@com.querydsl.core.annotations.QueryInit("*.*.*")
	@javax.persistence.ManyToOne(optional=false)
	private bairui.international.model.domain.jpa.TB_Province province;

	@com.lianjing.sh.model.common.annotation.Comment("名称")
	@com.lianjing.sh.processing.info.annotation.InfoComment("名称")
	@javax.persistence.Column(name="name", nullable=false, length=20)
	private String name;

	@com.lianjing.sh.model.common.annotation.Comment("代码")
	@com.lianjing.sh.processing.info.annotation.InfoComment("代码")
	@javax.persistence.Column(name="code", nullable=false, length=10)
	private String code;

	/** get[区县] */
	public java.util.List<bairui.international.model.domain.jpa.TB_Town> getTowns() {
		return this.towns;
	}

	/** get[省份] */
	public bairui.international.model.domain.jpa.TB_Province getProvince() {
		return this.province;
	}

	/** get[名称] */
	public String getName() {
		return this.name;
	}

	/** get[代码] */
	public String getCode() {
		return this.code;
	}

	/** set[区县] */
	public void setTowns(java.util.List<bairui.international.model.domain.jpa.TB_Town> towns) {
		this.towns = towns;
	}

	/** set[省份] */
	public void setProvince(bairui.international.model.domain.jpa.TB_Province province) {
		this.province = province;
	}

	/** set[名称] */
	public void setName(String name) {
		this.name = name;
	}

	/** set[代码] */
	public void setCode(String code) {
		this.code = code;
	}


	public void assignProvince(bairui.international.model.domain.jpa.TB_Province province) {
		if(null != province){
			province.addCities(this);
		}
		this.setProvince(province);
	}
	

	/** add[Towns] */
	public TB_City addTowns(bairui.international.model.domain.jpa.TB_Town ... towns){
		if(this.towns == null){
			this.towns = new java.util.ArrayList<>();
		}
		for(bairui.international.model.domain.jpa.TB_Town bean : towns){
			bean.setCity(this);
			this.towns.add(bean);
		}
		return this;
	}
	
	/** remove[Towns] */
	public TB_City removeTowns(bairui.international.model.domain.jpa.TB_Town ... towns){
		if(this.towns == null){
			return this;
		}
		for(bairui.international.model.domain.jpa.TB_Town bean : towns){
			bean.setCity(null);
			this.towns.remove(bean);
		}
		return this;
	}
	
	/**
	 * contains[Towns]
	 *
	 * 全部输入都包含：返回 true
	 * 输入中有至少有一个不包含：返回 false
	 */
	public boolean containsTowns(bairui.international.model.domain.jpa.TB_Town ... towns){
		if(this.towns == null || towns==null || towns.length<=0){
			return false;
		}
		return this.towns.containsAll(java.util.Arrays.asList(towns));
	}
	

	/** take[省份] */
	public bairui.international.model.domain.jpa.TB_Province takeProvince(){
		if(null == this.province){
			this.province = new bairui.international.model.domain.jpa.TB_Province();
		}
		return this.province;
	}
	
	/** must[省份] */
	public bairui.international.model.domain.jpa.TB_Province mustProvince() {
		return this.province;
	}
	
	

	/**
	 * 复写 hashCode
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		return prime * result + ((this.getId() == null) ? 0 : this.getId().hashCode());
	}
	
	/**
	 * 复写 equals
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj){
			return true;
		}
		if (obj == null){
			return false;
		}
		if (getClass() != obj.getClass()){
			return false;
		}
		TB_City other = (TB_City) obj;
		if (this.getId() == null) {
			return false;
		} else if (!this.getId().equals(other.getId())){
			return false;
		}
		return true;
	}
	

	/**
	 * 用来覆盖toString()的输出
	 */
	@javax.persistence.Transient
	private String toString;
	
	public void setToString(String toString) {
		this.toString = toString;
	}
	
	/**
	 * 复写 toString
	 */
	@Override
	public String toString() {
		if(null != this.toString){
			return this.toString;
		}
		String name = this.getName();
		if(null != name){
			return String.valueOf(name);
		}
		return super.toString();
	}	

	@javax.persistence.PrePersist
	public void prePersist() {
		this.setCreateTime(new java.util.Date());
		this.setModifyTime(new java.util.Date());
	}
	
	@javax.persistence.PreUpdate
	public void preUpdate() {
		this.setModifyTime(new java.util.Date());
	}



}
